#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 200010;
using ll = long long;
struct Node
{
    int l, r, maxv;
}tr[N * 4];
int m, p;
void pushup(int u)
{
    tr[u].maxv = max(tr[u << 1].maxv, tr[u << 1 | 1].maxv);
}
void build(int u, int l, int r)
{
    if (l == r) tr[u] = { l,r };
    else
    {
        tr[u] = { l,r };
        int mid = l + r >> 1;
        build(u << 1, l, mid);
        build(u << 1 | 1, mid + 1, r);
        pushup(u);
    }
}
void modify(int u, int xi, int v)
{
    if (tr[u].l == tr[u].r) tr[u].maxv = max(tr[u].maxv, v);
    else
    {
        int mid = tr[u].l + tr[u].r >> 1;
        if (xi <= mid) modify(u << 1, xi, v);
        else modify(u << 1 | 1, xi, v);
        pushup(u);
    }
}
int query(int u, int l, int r)
{
    if (tr[u].l >= l && tr[u].r <= r) return tr[u].maxv;
    int mid = tr[u].l + tr[u].r >> 1;
    int res = 0;
    if (l <= mid) res = query(u << 1, l, r);
    if (r > mid) res = max(res, query(u << 1 | 1, l, r));
    return res;
}
int main()
{
    cin >> m >> p;
    int n = 0, last = 0;
    build(1, 0, m - 1);
    while (m--)
    {
        char c;
        int x;
        cin >> c >> x;
        if (c == 'A')
        {
            modify(1, n++, (x + (ll)last) % p);
        }
        else
        {
            last = query(1, n - x, n - 1);
            cout << last << endl;
        }
    }
    return 0;
}